home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Idle DA's / Idle Notes next >
Encoding:
Text File  |  1986-11-05  |  2.4 KB  |  109 lines  |  [TEXT/MACA]

  1. Two more idle DAs.
  2.  
  3. Moire.da bounces two points (random speeds) and inscribes objects within the generated rectangles.
  4.  '[' and ']' shorten and lengthen the queue.  
  5. 'q' toggles speed quantization.
  6. '0' thru '9' set a speed limit for points ('0' means none).
  7. Other keys change shape:
  8. 'r' - rectangle (default for unassigned keys)
  9. 'o' - oval
  10. 'd' - diamond
  11. 't' - triangle
  12. 'p' - pentagram (for satanic users)
  13. 'h' - hourglass
  14. 'v' - a vee
  15. 'x' - an ex
  16. '/' & '\' - slanted lines
  17.  
  18. Poly.da bounces up to ten points and connects the dots.
  19. '[' and ']' shorten and lengthen the queue.
  20. 'q' toggles speed quantization
  21. '0' - '9' set the # points in the polygon ('0' and '1' mean 10)
  22.  
  23. The source consists of three files:
  24. idler.c - a common DA shell that may be used for writing other DAs.
  25. moire.c - drawing routines for moire.da
  26. poly.c - drawing routines for poly.da
  27.  
  28. Produced using LightSpeed* C!
  29.  
  30.  
  31. SHAR_EOF
  32. sed 's/^X//' << 'SHAR_EOF' > Idler.c
  33. /*
  34.  * shell routine for idle DAs
  35.  */
  36. #include <hd20:lightspeed:mac:DeviceMgr.h>
  37. #include <hd20:lightspeed:mac:WindowMgr.h>
  38. #include <hd20:lightspeed:mac:EventMgr.h>
  39. #include <hd20:lightspeed:mac:MenuMgr.h>
  40.  
  41. main(cp, dp, entry)
  42. cntrlParam *cp;
  43. DCtlPtr dp;
  44. int entry;
  45. {
  46.     EventRecord *ep;
  47.     static Rect screen;
  48.     static Handle menuH;
  49.     static WindowPtr windP;
  50.     static Boolean active = false;
  51.  
  52.  
  53.     if (!dp->dCtlStorage) {
  54.         if (!entry)
  55.             CloseDriver(dp->dCtlRefNum);
  56.         return 0;
  57.     }
  58.     switch (entry) {
  59.     case 0:    /* open */
  60.         dp->dCtlFlags |= dNeedLock | dNeedTime;
  61.         dp->dCtlDelay = 0;
  62.         dp->dCtlEMask = everyEvent;
  63.  
  64.         GetWMgrPort(&windP);
  65.         screen = windP->portRect;
  66.         windP = NewWindow(0L, &screen, "\p", true, noGrowDocProc, -1L, true, 0L);
  67.         RectRgn(windP->visRgn, &screen);
  68.         ((WindowPeek) windP)->windowKind = dp->dCtlRefNum;
  69.  
  70.         initIdle(&screen);
  71.         break;
  72.     case 2:    /* control */
  73.         SetPort(windP);
  74.         switch (cp->csCode) {
  75.         case accRun:
  76.             if (active)
  77.                 runIdle(&screen);
  78.             break;
  79.         case accEvent:
  80.             ep = (EventRecord *)*(long *)&cp->csParam; 
  81.             switch (ep->what) {
  82.             case activateEvt:
  83.                 menuH = GetMenuBar();
  84.                 ClearMenuBar();
  85.                 PaintRect(&screen);
  86.                 PenMode(patXor);
  87.                 active = true;
  88.                 break;
  89.             case keyDown:
  90.                 if (!active || keyIdle((int)(ep->message & charCodeMask)) >= 0)
  91.                     break;
  92.             case mouseDown:
  93.                 CloseDriver(dp->dCtlRefNum);
  94.                 break;
  95.             }
  96.             break;
  97.         }
  98.         break;
  99.  
  100.     case 4:    /* close */
  101.         DisposeWindow(windP);
  102.         SetMenuBar(menuH);
  103.         DisposHandle(menuH);
  104.         DrawMenuBar();
  105.         break;
  106.     }
  107.     return 0;
  108. }
  109.